# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/15 22:01
@Auth ： 叶东宇
@File ：fourSum.py
"""
def fourSum(l1,l2,l3,l4):
    """
    时间超时了
    """

    length = len(l1)
    li = []
    for i in range(length):
        for j in range(length):
            for k in range(length):
                for l in range(length):
                    if l1[i] + l2[j] + l3[k] + l4[l] == 0:
                        li.append([i,j,k,l])
    return li


def fourSum_(l1, l2, l3, l4):
    """
    时间超时了
    """
    length = len(l1)
    a = 0
    for i in range(length):
        for j in range(length):
            for k in range(length):
                a += l4.count(0-(l1[i] + l2[j] + l3[k]))
    return a

def from_leetcode(l1, l2, l3, l4):
    dic_1 = {}
    length = len(l1)
    a = 0
    for i in range(length):
        for j in range(length):
            if l1[i] + l2[j] not in dic_1:
                dic_1[l1[i] + l2[j]] = 0
            else:
                dic_1[l1[i] + l2[j]] += 1
    for i in range(length):
        for j in range(length):
            if 0 - (l3[i] + l4[j]) in dic_1:
                a += dic_1[l3[i] + l4[j]]
    return a